package model.juliStaff.propo;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Date: Sep 5, 2009 Time: 8:25:53 PM
 *
 * @author Maria Julia Racca;
 */

public class MolecularProposition extends AbstractProposition {

    private Proposition first;
    private Operation operation;
    private Proposition second;

    public MolecularProposition(Proposition first, Operation operations,
                                Proposition second, boolean isNot) {

        this.first = first;
        this.second = second;
        this.operation = operations;

        if (isNot) {
            this.negated = Operation.NOT;
        } else {
            this.negated = Operation.NON;
        }
    }

    public MolecularProposition(Proposition first2, Operation and,
                                Proposition second2, Operation operation2) {

        this.first = first2;
        this.second = second2;
        this.operation = and;
        this.negated = operation2;
    }

    //@Override
    public boolean equals(Object obj) {
        return compareTo((Proposition) obj) == 0;
    }

    public Proposition getFirst() {
        return first;
    }

    public Operation getOperation() {
        return operation;
    }

    public Proposition getSecond() {
        return second;
    }

    @Override
    public String toString() {

        StringBuffer sb = new StringBuffer();

        sb.append(negated.toString());
        sb.append("(");
        sb.append(first.toString());
        sb.append(" ");
        sb.append(operation.toString());
        sb.append(" ");
        sb.append(second.toString());
        sb.append(")");

        return sb.toString();
    }

    public void setFirst(Proposition first) {
        this.first = first;
    }

    public void setSecond(Proposition second) {
        this.second = second;
    }

    public void setOperation(Operation operation) {
        this.operation = operation;
    }

    @Override
    public int compareTo(Proposition p) {

        boolean n = negated.equals(p.getNegated());
        boolean equals = equals(p);

        if (!equals) {
            return -1;
        } else if (n) {
            return 0;
        }
        return 1;
    }

    @Override
    public boolean compare(Proposition obj) {

        if (obj == null || obj instanceof AtomicProposition) {
            return false;
        }

        MolecularProposition p = (MolecularProposition) obj;

        boolean f = first.equals(p.getFirst());
        boolean s = second.equals(p.getSecond());
        boolean o = operation.equals(p.getOperation());

        return f && s && o;
    }

}
